package com.suyafei.es.controller;

import com.suyafei.es.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @program: es-homework
 * @description
 * @author: luffy
 * @create: 2020-12-10 22:41
 */
@RestController
public class PositionController {
    @Autowired
    private PositionService positionService;

    @RequestMapping("/importAll")
    public String importAll() {

        try {
            positionService.importAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> searchPosition(@PathVariable("keyword") String keyword, @PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) throws IOException {
        System.out.println(keyword);
        List<Map<String, Object>> maps = positionService.searchPos(keyword, pageNo, pageSize);
        System.out.println("一共有5条数据"+maps.size());
        for (Map<String, Object> map : maps) {
            System.out.println(map.get("positionName"));
            System.out.println(map.get("positionAdvantage"));
            System.out.println("--------------");
        }
        return maps;
    }

}
